# -*- coding: utf-8 -*-
"""
****************************
@Time    : 2021/5/10 16:18
@Author  : Candy
@File    : get_area_by_ip.py
****************************
"""
import json
import requests


def get_area(ip):
    data = {}
    header = {
        "Accept": "*/*",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
    }
    res = requests.post(url='https://ip.taobao.com/outGetIpInfo?ip=%s&accessKey=alibaba-inc' % ip, data=data, headers=header)
    if res.status_code == 200:
        res_dat = json.loads(res.content.decode('utf-8'))
        r = '%s-%s省-%s市-%s' % (res_dat['data']['country'], res_dat['data']['region'], res_dat['data']['city'], res_dat['data']['isp'])
        if '内网IP' in r:
            return '内网登陆'
        return r
    else:
        return '未知'








